﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using YY.Basic;
using Infragistics.Win.UltraWinTree;
using TK3DSim;
using Tpro6Container.Mil;
using TK3DSim.Mil;

namespace Tpro6Container
{
    public partial class FormArmyBH : Form
    {
        public FormArmyBH()
        {
            InitializeComponent();
            Init();
        }

        private Image _Img = ResourceHelper.LoadImage("Tpro6Container.Resource.target.png");
        private void Init()
        {
            int iNO = 1;
            this.comOrg.Items.Add((Organizations)iNO + 0, Organizations.师.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.师))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.师);
            }
            this.comOrg.Items.Add((Organizations)iNO + 1, Organizations.旅.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.旅))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.旅);
            }
            this.comOrg.Items.Add((Organizations)iNO + 2, Organizations.团.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.团))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.团);
            }
            this.comOrg.Items.Add((Organizations)iNO + 3, Organizations.营.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.营))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.营);
            }
            this.comOrg.Items.Add((Organizations)iNO + 4, Organizations.连.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.连))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.连);
            }
            this.comOrg.Items.Add((Organizations)iNO + 5, Organizations.排.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.排))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.排);
            }
            this.comOrg.Items.Add((Organizations)iNO + 6, Organizations.蓝师.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.蓝师))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.蓝师);
            }
            this.comOrg.Items.Add((Organizations)iNO + 7, Organizations.蓝旅.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.蓝旅))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.蓝旅);
            }
            this.comOrg.Items.Add((Organizations)iNO + 8, Organizations.蓝团.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.蓝团))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.蓝团);
            }
            this.comOrg.Items.Add((Organizations)iNO + 9, Organizations.蓝营.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.蓝营))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.蓝营);
            }
            this.comOrg.Items.Add((Organizations)iNO + 10, Organizations.蓝连.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.蓝连))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.蓝连);
            }
            this.comOrg.Items.Add((Organizations)iNO + 11, Organizations.蓝排.ToString());
            if (!Global.Instance.GlobalArmyBHs.HaveExist(Organizations.蓝排))
            {
                Global.Instance.GlobalArmyBHs.Add(Organizations.蓝排);
            }
            this.comOrg.SelectedIndex = 0;

            for(int i = 0;i<  Global.Instance.GlobalArmyBHs.Count;i++)
            {
                ArmyBH ar =  Global.Instance.GlobalArmyBHs[i];

                if ((Organizations)this.comOrg.SelectedItem.DataValue == ar.Organization)
                {
                    txtModelName.Text = ar.FileName;
                    numModelZoom.Value = ar.FileScal;
                    numViewHeight.Value = ar.MaxV;
                    numModelViewHeight.Value = ar.MinV;
                }
             
            }
        }

    


        private void bSave_Click(object sender, EventArgs e)
        {
            //modify = false;
            for (int i = 0; i < Global.Instance.GlobalArmyBHs.Count; i++)
            {
                ArmyBH ar = Global.Instance.GlobalArmyBHs[i];

                if ((Organizations)this.comOrg.SelectedItem.DataValue == ar.Organization)
                {
                    ar.FileName = txtModelName.Text;
                    ar.FileScal = (double)numModelZoom.Value;
                    ar.MaxV = (double)numViewHeight.Value;
                    ar.MinV = (double)numModelViewHeight.Value;
                    Global.Instance.GlobalArmyBHs.UpdateData();
                }
                

            }

        }

        private void ultraButton5_Click(object sender, EventArgs e)
        {
            OpenFileDialog opend = new OpenFileDialog ();
            opend.Filter = "所有文件(*.*)|*.*";
             opend.InitialDirectory  = Application.StartupPath  +@"\img\";
            if (opend.ShowDialog() == DialogResult.OK)
            {
                txtModelName.Text = opend.FileName.Remove(0,opend.InitialDirectory.Length);
            }
           
        }

        private void comOrg_SelectionChanged(object sender, EventArgs e)
        {
            for (int i = 0; i < Global.Instance.GlobalArmyBHs.Count; i++)
            {
                ArmyBH ar = Global.Instance.GlobalArmyBHs[i];

                if ((Organizations)this.comOrg.SelectedItem.DataValue == ar.Organization)
                {
                    txtModelName.Text = ar.FileName;
                    numModelZoom.Value = ar.FileScal;
                    numViewHeight.Value = ar.MaxV;
                    numModelViewHeight.Value = ar.MinV;
                }

            }
        }
    }
}
